//
//  WBTabBarViewController.swift
//  微博
//
//  Created by 仲启明 on 2017/1/3.
//  Copyright © 2017年 swift. All rights reserved.
//

import UIKit

class WBTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let wbTabBar = WBTabBar()
        
        wbTabBar.composeClosure = { [weak self] in
            
          
        }
        
        setValue(wbTabBar, forKey: "tabBar")
        
        
        addChildControllers()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    private func addChildControllers(){
        
        addChildController(vc: WBHomeViewController(), title: "首页", imageName: "tabbar_home")
        addChildController(vc: WBMessageViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildController(vc: WBDiscoverViewController(), title: "发现", imageName: "tabbar_discover")
        addChildController(vc: WBProfileViewController(), title: "我", imageName: "tabbar_profile")
        
    }
    

    private func addChildController(vc: UIViewController, title: String, imageName: String){
        
        vc.tabBarItem.image = UIImage(named:imageName)
        vc.tabBarItem.selectedImage = UIImage(named:imageName + "_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orange], for: .selected)
        
        vc.tabBarItem.setTitleTextAttributes([NSFontAttributeName : UIFont.systemFont(ofSize: 10)], for: .normal)
        
        vc.tabBarItem.titlePositionAdjustment = UIOffset(horizontal:0, vertical:-3)
        
        vc.tabBarItem.badgeValue = "10"
        
        vc.tabBarItem.badgeValue = nil
        
        vc.tabBarItem.badgeColor = #colorLiteral(red: 0.5568627715, green: 0.3529411852, blue: 0.9686274529, alpha: 1)
        
        vc.tabBarItem.title = title
        
        vc.navigationItem.title = title
        
        let nav = WBNaviViewController(rootViewController:vc)
        
        
        self.addChildViewController(nav)
    }

}
